//和用户相关的函数

import myAxios from "@/plugins/myAxios";
import { showToast } from "vant";

//获取当前登录用户信息
const getCurrentUser = async () => {
  return await myAxios
    .get("/user/currentUser")
    .then(function (response) {
      return response;
    })
    .catch(function (error) {
      showToast(error.message);
    });
};

//更新用户信息
const updateUser = async (id, property, value) => {
  return await myAxios
    .post("/user/update", {
      id,
      [property]: value,
    })
    .then(function (response) {
      return response;
    })
    .catch(function (error) {
      showToast(error.message);
    });
};

//获取推荐用户
const recommendUser = async (pageNum, pageSize) => {
  return await myAxios
    .get("/user/recommend", {
      params: {
        pageNum,
        pageSize,
      },
    })
    .then(function (response) {
      return response;
    })
    .catch(function (error) {
      showToast(error.message);
    });
};

//获取匹配用户
const matchUser = async (num) => {
  return await myAxios
    .get("/user/match", {
      params: {
        num,
      },
    })
    .then(function (response) {
      return response;
    })
    .catch(function (error) {
      showToast(error.message);
    });
};

export { getCurrentUser, updateUser, recommendUser, matchUser };
